package com.michael.retail.auth.service;

import com.michael.retail.commons.constant.AuthConstant;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 类功能描述:
 * <pre>
 *   初始化资源与角色关系
 *   缓存到Redis中
 * </pre>
 *
 * @author Michael
 * @version 1.0
 * @date 2021/7/16 15:29
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class InitResourcesAndRoleService {

    private final RedisTemplate<String, Object> redisTemplate;

    private Map<String, String> adminAuthMap = new HashMap<>();

    @PostConstruct
    public void initResourcesAndRole() {

        adminAuthMap.put("/sys/hello/say", "aaa");
        adminAuthMap.put("/sys/hello/do", "bbb");
        adminAuthMap.put("/sys/hello/user", "ccc");

        redisTemplate.opsForHash().putAll(AuthConstant.AUTHORIZATION_REDIS_KEY_ADMIN, adminAuthMap);
    }
}
